package cas.ihep.alluxio.impl;

import cas.ihep.alluxio.AlluxioBlock;
import com.google.common.io.Closer;

import java.io.IOException;

public abstract class AlluxioBaseBlock implements AlluxioBlock {

    Closer mCloser;
    long mId;
    long mSize;
    boolean mClosed;
    String mPath;

    AlluxioBaseBlock(long id_, long sz){
        mCloser=Closer.create();
        mId =id_;
        mSize =sz;
        mClosed=false;
    }

    public long getBlockId(){
        return mId;
    }

    public long getBlockSize(){
        return mSize;
    }

    public String getBlockPath(){
        if (mClosed){
            throw new RuntimeException("already closed");
        }
        return mPath;
    }

    public abstract boolean canRead();
    public abstract boolean canWrite();
    public abstract void cancel()throws IOException;
    public abstract void require(long size)throws IOException;

}
